package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.enums.ApplicationTypeEnum;
import com.useeinfo.oa.modules.security.entity.SystemRole;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @Auther: xudong.sun
 * @Date: 2018/1/3 15:40
 * @Description: 应用
 */
@Entity
@Table(name = "ApplicationModule")
public class ApplicationModule extends SuperClassEntity<ApplicationModule> {


    /**
     * 应用名称
     */
    private String applicationName;
    /**
     * 应用图标--地址
     */
    private String icon;

    /**
     * 应用类型
     */
    @Enumerated(value = EnumType.STRING)
    private ApplicationTypeEnum applicationTypeEnum;
    /**
     * 跳转地址
     */
    private String url;

    /**
     * 标志字段   维修：REPAIR  维保:MAINTAIN  巡检：INSPECTION   任务单: TASK
     */
    private String remark;

    /**
     * 企业关联
     */
    @ManyToMany(mappedBy = "applicationModuleSet")
    private Set<Enterprise> enterpriseSet = new HashSet<>();


    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public ApplicationTypeEnum getApplicationTypeEnum() {
        return applicationTypeEnum;
    }

    public void setApplicationTypeEnum(ApplicationTypeEnum applicationTypeEnum) {
        this.applicationTypeEnum = applicationTypeEnum;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Set<Enterprise> getEnterpriseSet() {
        return enterpriseSet;
    }

    public void setEnterpriseSet(Set<Enterprise> enterpriseSet) {
        this.enterpriseSet = enterpriseSet;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject =  super.toJSONObject();
        jsonObject.put("applicationName", StringConverters.null2String(getApplicationName()));
        jsonObject.put("type",getApplicationTypeEnum()==null?"":getApplicationTypeEnum().getName());
        jsonObject.put("url", StringConverters.null2String(getUrl()));
        return jsonObject;
    }
}
